﻿

crucible.Node = function(data) {

    var self = this;
    data = data || {};

    this.Id = data.Id;
    this.Title = ko.observable(data.Title);
    this.Body = ko.observable(data.Body);
    this.AddedBy = ko.observable(data.AddedBy ? data.AddedBy : { UserId: data.AddedBy_UserId });
    this.Published = ko.observable(data.Published);
    this.Type = ko.observable(data.Type || crucible.NodeType.assertion);
    this.Link = ko.observable(data.Link);
    this.Source = ko.observable(data.Source);
    this.Agreement = ko.observable(data.Agreement || 0);
    this.Logic = ko.observable(data.Logic || 0);
    
    this.FormattedBody = ko.computed(function () {
        return crucible.NodeHelper.bodyConverter.convert(self);
    });

    this.IsEditing = ko.observable();
    this.hydrated = false;

};

crucible.Node.prototype.freshData = function (data) {

    this.Id = data.Id;
    this.Title(data.Title);
    this.Body(data.Body || this.Body());
    this.Published(data.Published);
    this.Type(data.Type || this.Type());
    this.AddedBy(data.AddedBy ? data.AddedBy : { UserId: data.AddedBy_UserId });
    this.Link(data.Link);
};

